#include<bits/stdc++.h>
using namespace std;
int t,n,m,L,V,d[100005],v[100005],a[100005],p[100005],y[100005],ans;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n>>m>>L>>V;
        for(int i = 1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i = 1;i<=m;i++){
            cin>>p[i];
        }
        bool flag=false;
        for(int i = 1;i<=n;i++){
            for(int j = 1;j<=m;j++){
                if(v[i]<=V)continue;
                if(p[j]>=d[i]){
                    flag=true;
                    y[j]++;
                }
                if(flag==true)ans++;
            }
        }
        int maxm=0,maxi=0;
        for(int i = 1;i<=m;i++){
            if(maxm<y[i]){
                maxm=y[i];
                maxi=i;
            }
        }
        cout<<ans<<" ";
        if(maxm==ans)cout<<m-1<<endl;
        else cout<<m-maxm<<endl;
    }
    return 0;
}

